package com.powernode.interceptor;

import com.powernode.common.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute(Constants.SESSION_USER_KEY);
        if (null!=user) {
            return true;
        }else {
            response.sendRedirect(request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() +request.getContextPath()+"/"+"index.html");
            return false;
        }
    }
}
